home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 4 / BBS in a Box - Macintosh - Volume IV (January 1992) (BBS in a Box).iso / Files / Prog / N-P / ProtoClip.sea / main.c / main.c
Encoding:
C/C++ Source or Header  |  1991-04-21  |  2.2 KB  |  145 lines  |  [TEXT/KAHL]

  1. /*
  2.     main.c
  3.     
  4.     by Alex D. Chaffee (adc)
  5.     (chaffee@reed.bitnet, AOL:AlexCh, CIS:71210,1117)
  6.     
  7.     Copyright © 1991 Alex Chaffee. Permission granted to change and 
  8.     distribute freely, provided all changes are documented.
  9.     
  10.     protoclip fkey (+ app)
  11. */
  12.  
  13. #include "config.h"            /*    There is a different copy of this file
  14.                             for the application and fkey projects.
  15.                             Each contains specific #defines.
  16.                         */
  17. #ifdef FKEY
  18.     #include <SetUpA4.h>
  19. #else
  20.     #include <stdio.h>
  21.     #include <console.h>
  22.     #include <profile.h>
  23. #endif
  24. #include "main.h"
  25. #include "proto.h"
  26. #include "hfile.h"
  27.  
  28. void main(void);
  29. #ifdef DEBUG
  30.     void DebugNum(long e);
  31. #endif
  32.  
  33. #ifdef DEBUG
  34.     #define CheckHeap();        \
  35.         NewHandle(0); asm{nop};
  36. #else
  37.     #define CheckHeap()
  38. #endif
  39.  
  40. void main(void)
  41. {
  42.     Handle    handIn, handOut;
  43.     long    lenIn, lenOut;
  44.     long    offset;
  45.     Boolean fOkay;
  46.     
  47. #ifdef FKEY
  48.     RememberA0();
  49.     SetUpA4();
  50. #endif
  51.  
  52. #ifdef APP
  53.     console_options.nrows = 14;
  54.     printf("Protoclip!\n");
  55. #endif
  56. #ifdef PROFILE
  57.     printf("Profiling...\n");
  58.     InitProfile(200,200);
  59. #endif
  60.  
  61.     SetCursor(*GetCursor(watchCursor));
  62.     ShowCursor();
  63.  
  64.     LoadScrap();
  65.     
  66. /*    If we're running as an application, just take the system clipboard    */
  67. #ifndef APP
  68.     if (0L < TEGetScrapLen()) {    /* if we're using the TE Scrap    */
  69.         ZeroScrap();
  70.         TEToScrap();
  71.     }
  72. #endif
  73.     if (0L == (handIn = NewHandle(0L)) ||
  74.         0L >= (lenIn = GetScrap(handIn,'TEXT',&offset))) {
  75.         DisposHandle(handIn);
  76.         SysBeep(10);
  77.         goto leave;
  78.     }
  79.  
  80.     handOut = NewHandle(0);
  81.  
  82.     fOkay = proto(handIn, handOut) == 0;
  83.  
  84.     HUnlock(handIn);
  85.     DisposHandle(handIn);
  86.  
  87. /*    DebugNum((long)*handOut);    */
  88.  
  89.     if (fOkay)
  90.     {    
  91.         HLock(handOut);
  92.  
  93.         ZeroScrap();
  94.  
  95.         lenOut = GetHandleSize(handOut);
  96.  
  97.         PutScrap(lenOut ,'TEXT', *handOut);
  98.  
  99.         if (0L < TEGetScrapLen())
  100.             TEFromScrap();
  101.     }
  102.     else
  103.         SysBeep(8);
  104.  
  105. #ifdef APP
  106.     /*    print contents of handOut    */
  107.     {
  108.         long i;
  109.         char ch;
  110.         HLock(handOut);
  111. CheckHeap();
  112.         for (i=0; i<GetHandleSize(handOut); ++i)
  113.         {
  114. CheckHeap();
  115.             ch = *((*handOut)+i);
  116. CheckHeap();
  117.             if (ch == '\r')    putchar('\n');
  118.             else                putchar(ch);
  119.         }
  120. CheckHeap();
  121.         putchar('\n');
  122.     }
  123. #endif
  124.  
  125.     HUnlock(handOut);
  126.     DisposHandle(handOut);
  127.  
  128. leave:
  129.     InitCursor();
  130.  
  131. #ifdef FKEY
  132.     RestoreA4();
  133. #endif
  134.     return;    
  135. }
  136.  
  137. #ifdef DEBUG
  138. void DebugNum(long e)
  139. {
  140.     Str255 st;
  141.     NumToString(e, st);
  142.     DebugStr(st);
  143. }
  144. #endif
  145.